package com.yunnuo.sysmonitor.controller;

import com.yunnuo.common.controller.BaseController;
import com.yunnuo.common.web.ResultData;
import com.yunnuo.common.web.page.TableDataInfo;
import com.yunnuo.sysmonitor.domain.Logininfo;
import com.yunnuo.sysmonitor.service.ILogininfoService;
import net.sf.json.JSON;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @api {title} 系统访问记录comtroller
 * @apiName LogininfoController
 * @apiGroup System-LogininfoController
 * @apiDescription Created by 魏洪福(15064000912@163.com) on  2018/6/3.
 */
@Controller
@RequestMapping("/sysmonitor/logininfo")
public class LogininfoController extends BaseController {

    private String prefix = "sysmonitor/logininfo";

    @Autowired
    private ILogininfoService logininfoService;

    @RequiresPermissions("sysmonitor:logininfo:view")
    @GetMapping()
    public String logininfo()
    {
        return prefix + "/logininfo";
    }

    @RequiresPermissions("sysmonitor:logininfo:list")
    @GetMapping("/list")
    @ResponseBody
    public TableDataInfo list(Logininfo logininfo)
    {
        startPage();
        List<Logininfo> list = logininfoService.selectlogininfoList(logininfo);
        return getDataTable(list);
    }

    @RequiresPermissions("sysmonitor:logininfo:batchRemove")
    @PostMapping("/batchRemove")
    @ResponseBody
    public JSON batchRemove(@RequestParam("ids[]") Long[] ids)
    {
        ResultData data = new ResultData();
        if (logininfoService.batchDeletelogininfo(ids)>0)
        {
            data.setData("");
            data.setStat(ResultData.STAT_SUCCESS);
            data.setMessage("操作成功！");
        }else{
            data.setStat(ResultData.STAT_FAILURE);
            data.setData("");
            data.setMessage("操作失败！");
        }
        return data.toJson();
    }
}
